﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_RoomStatusSrhForm
 * 类型：       房态信息查询
 * 功能说明：   检索
 * 作者：       谈震鸣
 * 创建日期：   2007/08/22
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
 */
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OWC11;
using Shpm.App.Master.Bean;
using Shpm.System;
using Shpm.App.Search.Bean;
using Shpm.App.Search.Dao;
using Shpm.App.Commons.Utils;
using Shpm.System.Db;


public partial class App_Input_RoomStatusSrhForm : System.Web.UI.Page
{
    static private string shidTid = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            if (!string.IsNullOrEmpty((string)(Request.QueryString["tID"])))
            {
                shidTid = (string)(Request.QueryString["tID"]);
            }

            if (string.IsNullOrEmpty(Request.QueryString["buildingNo"]))
            {
                int bNo = 1;
                hidBuildingNo.Value = bNo.ToString();
                this.bNo.InnerText = "1";
            }
            else
            {
                int bNo = Convert.ToInt32(Request.QueryString["buildingNo"]);
                hidBuildingNo.Value = bNo.ToString();
                this.bNo.InnerText = Convert.ToString(Request.QueryString["buildingNo"]);
            }
        }

        if (!"".Equals(hidBuildingNo.Value))
        {
                try
                {
                    int no = int.Parse(hidBuildingNo.Value);
                    if( no == 1|| no == 2)
                    {
                        this.Table1.Visible = true;
                        this.Table2.Visible = false;
                        this.Table3.Visible = false;
                        SetColor(hidBuildingNo.Value, this.Table1);
                    }
                    else if (no == 3 || no == 4)
                    {
                        this.Table1.Visible = false;
                        this.Table2.Visible = true;
                        this.Table3.Visible = false;
                        SetColor(hidBuildingNo.Value, this.Table2);
                    }
                    else if ( 5<=no && no<=9 )
                    {
                        this.Table1.Visible = false;
                        this.Table2.Visible = false;
                        this.Table3.Visible = true;
                        SetColor(hidBuildingNo.Value, this.Table3);
                    }
                    else 
                    {
                        this.roomTable.Visible = false;
                    }
                }
                catch(Exception es)
                {
                    throw new DataAccessException(es);
                }
        }
    }

    private void SetColor(string bNo,Table table)
    {
        SalesInfoDao dao = new SalesInfoDao();
        SalesInfoBean salesInfoBean = new SalesInfoBean();
        salesInfoBean.BuildingNo = bNo;
        IList roomList = dao.FindBuildDetail(salesInfoBean);
        IList roomPersonList = dao.FindRoomPerson(salesInfoBean);

        System.Drawing.ColorConverter cc = new System.Drawing.ColorConverter();
        string roomNo = "";

        if (roomList != null && roomList.Count > 0)
        {
            for (int i = 1; i < table.Rows.Count; i++)
            {
                TableRow r = table.Rows[i];
                for (int j = 1; j < r.Cells.Count; j++)
                {
                    TableCell c = r.Cells[j];
                    if (!"&nbsp;".Equals(c.Text))
                    {
                        roomNo = string.Format("{0:00}", int.Parse(bNo)) + string.Format("{0:0000}", int.Parse(c.Text));
                        IEnumerator iem = roomList.GetEnumerator();

                        IEnumerator iem2 = roomPersonList.GetEnumerator();

                        SalesInfoBean bean = null;
                        LinkButton lb = new LinkButton();
                        lb.Text = c.Text;
                        lb.Command += new CommandEventHandler(this.LinkButton_Command);
                        string tip = "";
                        //lb.ToolTip = "xxx(yd) \n yyy(fd)";

                        ////
                        while (iem2.MoveNext())
                        {
                            bean = (SalesInfoBean)iem2.Current;
                            if (roomNo.Equals(bean.ApartmentNo))
                            {
                                //lb.CommandName = bean.StatusNo;
                                //tip += bean.NameC;
                                switch (bean.StatusNo)
                                {
                                    case "1":
                                    case "01":
                                        tip += "销售员：" + bean.EmployeeName + "--" + "客户：" + bean.NameC + "(意向)\n";

                                        break;

                                    case "3":
                                    case "03":
                                        tip += "销售员：" + bean.EmployeeName + "--" + "客户：" + bean.NameC + "(订付)\n";
                                        break;
                                  
                                    case "4":
                                    case "04":
                                        tip += "销售员：" + bean.EmployeeName + "--" + "客户：" + bean.NameC + "(入住)\n";
                                        break;
                                }
                            }
                        }
                        lb.ToolTip = tip;
                        //

                        while (iem.MoveNext())
                        {
                            bean = (SalesInfoBean)iem.Current;
                            if (roomNo.Equals(bean.ApartmentNo))
                            {
                                switch (bean.StatusNo)
                                {
                                    case "1":
                                    case "01":
                                        /*存在意向的*/
                                        if (!string.IsNullOrEmpty(bean.SaleApartmentNo))
                                        {
                                            lb.CommandName = "意向";
                                            c.BackColor = (System.Drawing.
                                          Color)cc.ConvertFromString("#ff0000");
                                        }
                                        else 
                                        {
                                            lb.CommandName = "待租";
                                            c.BackColor = (System.Drawing.
                                          Color)cc.ConvertFromString("#9acd32");
                                        }

                                        break;
                                    case "2":
                                    case "02":
                                        lb.CommandName = "付订";
                                        c.BackColor = (System.Drawing.
                                            Color)cc.ConvertFromString("#ba55d3");
                                        break;
                                  
                                    case "3":
                                    case "03":
                                        lb.CommandName = "入住";
                                        c.BackColor = (System.Drawing.
                                            Color)cc.ConvertFromString("#a9a9a9");
                                        break;
                                }
                                c.Controls.Add(lb);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    protected void LinkButton_Command(object sender, CommandEventArgs e)
    {
        //Context.Items["STATUS_NO"] = (sender as LinkButton).CommandName;
        //Context.Items["APARTMENT_NO"] = string.Format("{0:00}", int.Parse(hidBuildingNo.Value)) + string.Format("{0:0000}", int.Parse((sender as LinkButton).Text));
        // Context.Items["buildingNo"] = hidBuildingNo.Value;
        // ControllerUtils.Transfer(this.Context, "~/App/Search/RoomDetailsInfoForm.aspx", true);

         //GridViewRow row = GridView1.SelectedRow;
        string TxtVal = this.bNo.InnerText.Trim().PadLeft(2, '0') + (sender as System.Web.UI.WebControls.LinkButton).Text.Trim().PadLeft(4, '0'); //row.Cells[1].Text;
        Response.Write("<script language=JavaScript> window.opener.settext('" + shidTid + "','" + TxtVal + "');</script>");
        Response.Write("<script language=JavaScript> window.close();</script>");

    }
 
}
